package timbap.artwork.retrieval;

import javax.swing.JToggleButton;
import java.util.List;

public class QueryCreator {

    private static QueryCreator INSTANCE;

    public String createQuery(List<JToggleButton> pQueryTermButtons, final boolean pPhrased) {
        StringBuilder sb = new StringBuilder();
        for (JToggleButton tQueryTermButton : pQueryTermButtons) {
            if (tQueryTermButton.isSelected()) {
                sb.append(tQueryTermButton.getText()).append(" ");
            }
        }
        if (sb.length() > 0) {
            sb.deleteCharAt(sb.length() - 1);
            if (pPhrased) {
                sb.insert(0, "\"");
                sb.append("\"");
            }
        }
        return sb.toString();
    }

    public static QueryCreator getInstance() {
        if (INSTANCE == null) {
            INSTANCE = new QueryCreator();
        }
        return INSTANCE;
    }
}
